#!/usr/bin/python

from Crypto.Protocol import AllOrNothing
from Crypto.Cipher import AES
import getpass, md5

# get and pad password
passwd = getpass.getpass()
passwd = md5.md5(passwd).digest()

# set up cipher and block digest
cipher = AES.new(passwd)
block  = AllOrNothing.AllOrNothing(AES)

# read text
text = raw_input("enter a line of text> ")

# encryption works like this
enc = map(cipher.encrypt, block.digest(text))
print "encrypted version", repr(enc)

# decryption looks like this
dec = block.undigest(map(cipher.decrypt, enc))
print "decrypted version", repr(dec)

